import type { FormRules } from 'naive-ui'
import type { CreateFormItemsOptions } from '@/types/fcform'

export const createRules = (options: CreateFormItemsOptions): FormRules | Ref<FormRules> => {
  const { formData } = options

  return computed<FormRules>(() => {
    return {
      publicName: [
        {
          required: true,
          message: '标题不能为空',
          trigger: 'blur',
        },
      ],
      publicKey: [
        {
          required: true,
          message: '标识不能为空',
          trigger: 'blur',
        },
      ],
      publicValue: [
        {
          type: (formData.value.publicKey as string).includes('NUMBER') ? 'number' : 'string',
          required: true,
          message: '内容不能为空',
          trigger: 'blur',
        },
      ],
    }
  })
}
